package io.renren.modules.app.controller;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.Article;
import io.renren.modules.app.service.ArticleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 文章表
 *
 * @author chenjiacheng
 * @email 
 * @date 2019-02-11 19:04:20
 */
@RestController
@RequestMapping("app/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("app:article:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = articleService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{articleId}")
    @RequiresPermissions("app:article:info")
    public R info(@PathVariable("articleId") Integer articleId){
			Article article = articleService.selectById(articleId);

        return R.ok().put("article", article);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("app:article:save")
    public R save(@RequestBody Article article){
			articleService.insert(article);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("app:article:update")
    public R update(@RequestBody Article article){
			articleService.updateById(article);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("app:article:delete")
    public R delete(@RequestBody Integer[] articleIds){
			articleService.deleteBatchIds(Arrays.asList(articleIds));

        return R.ok();
    }

}
